require "rubygems"
require "ai4r"

net = Ai4r::NeuralNetwork::Backpropagation.new([2, 1])

exemple = [[0,0],[0,1],[1,0],[1,1]]
result  = [[1],[1],[0],[0]]    

puts "Treinando a rede..."
100.times do
	4.times do |i|
		error = net.train(exemple[i], result[i])  
	end
end  

def result_label(result)
  if result[0] < 0.5
	"FEMININO"
	else  
	"MASCULINO"
  end  
end

puts "Exemplos de treino"
puts "Jose #{net.eval([0,0]).inspect} => #{result_label(net.eval([0,0]))}"
puts "Paulo #{net.eval([0,1]).inspect} => #{result_label(net.eval([0,1]))}"
puts "Maria #{net.eval([1,0]).inspect} => #{result_label(net.eval([1,0]))}"
puts "Lucia #{net.eval([1,1]).inspect} => #{result_label(net.eval([1,1]))}"